package com.felhr.serialportexample.utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.widget.TextView;

public class ChoiceDialogManage {
    private Activity mActivity;
    private OnChoiceItemListenr choiceItemListenr;

    public ChoiceDialogManage(Activity mActivity, OnChoiceItemListenr choiceItemListenr) {
        this.mActivity = mActivity;
        this.choiceItemListenr = choiceItemListenr;
    }

    public void showChoiceDialog(String[] items, TextView setView, int flag) {
        AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
        builder.setItems(items, ((dialogInterface, position) -> {
            dialogInterface.dismiss();
            setView.setText(items[position]);
            if (choiceItemListenr != null) choiceItemListenr.onChoiceItem(flag, position);
        })).create().show();
    }

    public interface OnChoiceItemListenr {
        void onChoiceItem(int flag, int position);
    }
}